<?php

namespace addons\mental\model;

use think\Model;


class Config extends Model
{
    // 表名
    protected $name = 'mental_config';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;
    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;
    // 追加属性
    protected $append = [];

    /**
     * Undocumented function
     * 获取配置
     * @param string $name
     * @return void
     */
    public static function getVal($name = '')
    {
        if (empty($name)) {
            $data = self::field('name,t_name,value,content')->select();
            if (empty($data)) {
                return [];
            }
            $newData = [];
            foreach ($data as $val) {
                if ($val['name']) {
                    $newData[$val['name']] = $val['value'];
                }
                if ($val['t_name']) {
                    $newData[$val['t_name']] = $val['content'];
                }
            }
            return $newData;
        }
        return self::field('name,value,content')->where('name', '=', $name)->find();
    }
}
